<?php
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

require_once('modules/Calendar/Calendar.php');
class edanz_Schedule extends Calendar 
{
	var $module_dir = 'edanz_Schedule';
	var $object_name = 'edanz_Schedule';
	var $importable = false;
	var $disable_vardefs = true;
	//var $view = 'month';

	// Constructor for module installation. By PanJun(Sim)
	function edanz_Schedule($view = null, $time_arr = array()) {
		if (isset($view)) {
			parent::Calendar($view, $time_arr);	
		}
	}

	function create_slices()
	{
		$days_in_range = 13;

		for($i=0;$i<$days_in_range;$i++)
		{
			$slice = new Slice('day',$this->date_time->get_day_by_days_from_today($i));
			$this->slice_hash[$slice->start_time->get_mysql_date()] = $slice;
			array_push($this->slices_arr,  $slice->start_time->get_mysql_date());
		}
	}

	function get_end_slice_idx()
        {
		return 12;
	}

        function add_activities($user,$type='sugar') {
                $end_date_time = $this->date_time->get_day_by_days_from_today($this->get_end_slice_idx());

                $acts_arr = array();
                $acts_arr = CalendarActivity::get_activities($user->id, $this->show_tasks, $this->date_time, $end_date_time, $this->view);

            // loop thru each activity for this user
                for ($i = 0;$i < count($acts_arr);$i++) {
                        $act = $acts_arr[$i];
                        // get "hashed" time slots for the current activity we are looping through
                        $hash_list =DateTimeUtil::getHashList($this->view,$act->start_time,$act->end_time);

                        for($j=0;$j < count($hash_list); $j++) {
                                if(!isset($this->slice_hash[$hash_list[$j]]) || !isset($this->slice_hash[$hash_list[$j]]->acts_arr[$user->id])) {
                                        $this->slice_hash[$hash_list[$j]]->acts_arr[$user->id] = array();
                                }
                                $this->slice_hash[$hash_list[$j]]->acts_arr[$user->id][] = $act;
                        }
                }
        }

}
